// ProviderDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ProviderDlg.h"
#include "RealObject/Provider.h"
#include "MySQL/ProviderTbl.h"


// CProviderDlg dialog

IMPLEMENT_DYNAMIC(CProviderDlg, CDialog)

CProviderDlg::CProviderDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CProviderDlg::IDD, pParent)
	, m_sID(_T(""))
	, m_sName(_T(""))
	, m_sAddress(_T(""))
	, m_sPhone(_T(""))
	, m_sFax(_T(""))
	, m_sConnect(_T(""))
{

}

CProviderDlg::~CProviderDlg()
{
}

void CProviderDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_ID, m_sID);
	DDX_Text(pDX, IDC_EDIT_NAME, m_sName);
	DDX_Text(pDX, IDC_EDIT_ADDRESS, m_sAddress);
	DDX_Text(pDX, IDC_EDIT_PHONE, m_sPhone);
	DDX_Text(pDX, IDC_EDIT_FAX, m_sFax);
	DDX_Text(pDX, IDC_EDIT_CONNECT, m_sConnect);
}


BEGIN_MESSAGE_MAP(CProviderDlg, CDialog)
	ON_BN_CLICKED(IDC_BUTT_UPDATE, &CProviderDlg::OnBnClickedButtUpdate)
END_MESSAGE_MAP()


// CProviderDlg message handlers
BOOL CProviderDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
		
	int nMaxcode = CProviderTbl::getMaxCode();
	m_sID.Format(_T("NCC%.4d"),nMaxcode+1);
	UpdateData(FALSE);
	return TRUE;
}
void CProviderDlg::OnBnClickedButtUpdate()
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CProvider* pProvider = new CProvider;
	pProvider->setId(m_sID);
	pProvider->setName(m_sName);//name	
	pProvider->setAdress(m_sAddress);//Addrress
	pProvider->setMobile(m_sPhone);//mobile
	pProvider->setFax(m_sFax);//fax
	pProvider->setNote(m_sConnect);//note
	if(CProviderTbl::insertProvider(pProvider))
		CDialog::OnOK();
}
